import tkinter
import time
from tkinter import messagebox

a = 0
b = 0
c = 0
d = 0
e = 0
f = 0

clock_start = False

# 0代表普通模式
# 1代表倒计时模式
# 2代表游戏模式
mode_now = 0


def clock():
    global a, b, c, d, e, f
    clock_return = ("%i%i:%i%i:%i%i" % (a, b, c, d, e, f))
    if f != 9:
        f += 1
    else:
        if e != 5:
            e += 1
            f = 0
        else:
            if d != 9:
                d += 1
                e = 0
                f = 0
            else:
                if c != 5:
                    c += 1
                    d = 0
                    e = 0
                    f = 0
                else:
                    if b != 9:
                        b += 1
                        c = 0
                        d = 0
                        e = 0
                        f = 0
                    else:
                        a += 1
                        b = 0
                        c = 0
                        d = 0
                        e = 0
                        f = 0
    return clock_return


# 透明模式关闭按钮指令
def button_alpha_off_mes():
    window.wm_attributes("-alpha", 1)
    button_alpha.place_forget()
    button_alpha_on.place(x=0, y=0)
    label_alpha.config(text="现为普通模式")


# 透明模式开启按钮指令
def button_alpha_on_mes():
    window.wm_attributes("-alpha", 0.7)
    button_alpha_on.place_forget()
    button_alpha.place(x=0, y=0)
    label_alpha.config(text="现为透明模式")


# 取消置顶按钮指令
def button_top_off_mes():
    window.wm_attributes("-topmost", False)
    button_top.place_forget()
    button_top_on.place(x=192, y=0)
    label_topmost.config(text="现为取消置顶")


# 窗口置顶按钮指令
def button_top_on_mes():
    window.wm_attributes("-topmost", True)
    button_top_on.place_forget()
    button_top.place(x=192, y=0)
    label_topmost.config(text="现为窗口置顶")


# 调取系统时间并显示
def label_time_com():
    time_now = time.strftime("%H:%M:%S", time.localtime(time.time()))
    label_time.config(text=time_now)
    window.update()
    label_time.after(100, label_time_com)


# 计时器
def label_clock_com():
    if clock_start:
        clock_now = clock()
        label_clock.config(text=clock_now)
    window.update()
    label_clock.after(1000, label_clock_com)


# 开始计时按钮指令
def button_clock_start_mes():
    global clock_start
    clock_start = True


# 停止计时按钮指令
def button_clock_pause_mes():
    global clock_start
    clock_start = False


# 重置计时按钮指令
def button_clock_restart_mes():
    global a, b, c, d, e, f
    a = b = c = d = e = f = 0
    label_clock.config(text="00:00:00")
    button_clock_pause_mes()


# 版本信息按钮指令
def button_edition_mes():
    messagebox.showinfo("版本信息",
                        "版本：e-2.0\n"
                        "作者：PekingMan\n"
                        "更新日期：2020/4/13")


# 模式检测
def mode_verify():
    if mode_now == 0:
        return "现在是普通模式"
    elif mode_now == 1:
        return "现在是倒计时模式"
    elif mode_now == 2:
        return "现在是游戏模式"


# 更多功能按钮指令
def button_more_function_mes():
    more_function_window = tkinter.Tk()
    more_function_window.title("更多功能")
    more_function_window.geometry("250x50")
    more_function_window.resizable(height=False, width=False)
    more_function_window.iconbitmap("icon.ico")

    # 模式显示标签
    function_window_label_function = tkinter.Label(more_function_window, text=mode_verify())
    function_window_label_function.pack()
    function_window_label_function.after(100, mode_verify)

    more_function_window.mainloop()


# 窗口创建
window = tkinter.Tk()
window.title("Timer")
window.geometry("250x110")  # 窗口大小，长250，宽100
window.resizable(height=False, width=False)  # 让窗口高与宽为定值
window.wm_attributes("-topmost", True)  # 窗口置顶
window.wm_attributes("-alpha", 0.7)  # 窗口透明度为0.7
window.iconbitmap("icon.ico")

# 普通模式按钮
button_alpha = tkinter.Button(text="普通模式", height=1, width=7, command=button_alpha_off_mes)
button_alpha.place(x=0, y=0)

# 透明模式按钮
button_alpha_on = tkinter.Button(text="透明模式", height=1, width=7, command=button_alpha_on_mes)

# 取消置顶按钮
button_top = tkinter.Button(text="取消置顶", height=1, width=7, command=button_top_off_mes)
button_top.place(x=192, y=0)

# 窗口置顶按钮
button_top_on = tkinter.Button(text="窗口置顶", height=1, width=7, command=button_top_on_mes)

# 开始计时按钮
button_clock_start = tkinter.Button(text="开始计时", height=1, width=7, command=button_clock_start_mes)
button_clock_start.place(x=0, y=50)

# 停止计时按钮
button_clock_pause = tkinter.Button(text="停止计时", height=1, width=7, command=button_clock_pause_mes)
button_clock_pause.place(x=0, y=80)

# 重置计时按钮
button_clock_restart = tkinter.Button(text="重置计时", height=1, width=7, command=button_clock_restart_mes)
button_clock_restart.place(x=192, y=50)

# 版本信息按钮
button_edition = tkinter.Button(text="版本信息", height=1, width=7, command=button_edition_mes)
button_edition.place(x=192, y=80)

# 更多功能按钮
button_more_function = tkinter.Button(text="更多功能", height=1, width=7, command=button_more_function_mes)
button_more_function.place(x=95, y=80)

# 时间显示标签
label_time = tkinter.Label(text=time.strftime("%H:%M:%S", time.localtime(time.time())), font=("Arial", 10))
label_time.place(x=95, y=15)
label_time.after(100, label_time_com)

# 现在的时间是
label_time_now = tkinter.Label(text="现在的时间是", font=("Arial", 8))
label_time_now.pack()

# 透明模式或普通模式标签
label_alpha = tkinter.Label(text="现为透明模式", font=("Arial", 8))
label_alpha.place(x=0, y=30)

# 窗口置顶或取消置顶标签
label_topmost = tkinter.Label(text="现为窗口置顶", font=("Arial", 8))
label_topmost.place(x=180, y=30)

# 计时器标签
label_clock = tkinter.Label(text=clock(), font=("Arial", 23), fg="red")
label_clock.place(x=60, y=45)
label_clock.after(1000, label_clock_com)

# 模式标签
label_function = tkinter.Label(text="现为普通模式", font=("Arial", 8))
label_function.place(x=90, y=33)

window.mainloop()
